<template>
    <base-breadcrumb>
        <searchData :searchData="searchArr" @search="search"></searchData>
        <a-card :bordered="false">
            <list-table
                ref="table"
                :columns="columns"
                :request="loadData"
            >
                <template slot="prefix" slot-scope="ref">
                    <a-button type="primary" icon="plus" @click="$nav('add')">新增</a-button>
                </template>
                <span slot="index" slot-scope="text, record, index">{{ index + 1 }}</span>
                <template slot="auditStatusStr" slot-scope="text, record, index">
                    <list-status :status="record.auditStatus" :text="text"></list-status>
                </template>
                <template slot="operation" slot-scope="text, record, index">
                    <MoreButton class="pub-table-list-action">
                        <a @click="$nav('add',{id:record.id,detail:1})">查看</a>
                        <template v-if="record.auditStatus === 'DRAFT' || record.auditStatus === 'REJECTED'">
                            <a @click="$nav('add',{id:record.id})">编辑</a>
                            <a @click="handleDel(record.id)">删除</a>
                        </template>
                        <approval-button :status="record.auditStatus" :id="record.id"></approval-button>
                    </MoreButton>
                </template>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import hardWorkApi from '@/api/union/employeeCare/hardWorkApi'
import BSelect from '@/components/BComponents/BSelect'

export default {
    name:'a'+Date.now(),
    
    data() {
        return {
            columns: [
                {
                    title: '序号',
                    dataIndex: 'index',
                    width: 70,
                    scopedSlots: { customRender: 'index' }
                },
                {
                    title: '层级',
                    dataIndex: 'levelName',
                    width: 150
                },
                {
                    title: '单位',
                    dataIndex: 'depName',
                    width: 120
                },
                {
                    title: '姓名',
                    dataIndex: 'name',
                    width: 150
                },
                {
                    title: '性别',
                    dataIndex: 'sex',
                    width: 150
                },
                {
                    title: '身份证号码',
                    dataIndex: 'idCard',
                    width: 180
                },
                {
                    title: '困难级别',
                    dataIndex: 'hardLevel',
                    width: 150
                },
                {
                    title: '入职时间',
                    dataIndex: 'entryTime',
                    width: 150
                },
                {
                    title: '申请时间',
                    dataIndex: 'createTime',
                    width: 150
                },
                {
                    title: '审核状态',
                    dataIndex: 'auditStatusStr',
                    scopedSlots: { customRender: 'auditStatusStr' },
                    width: 150
                },
                {
                    title: '操作',
                    width: 200,
                    fixed: 'right',
                    scopedSlots: { customRender: 'operation' }
                }
            ],
            searchArr: [
                // 搜索框
                {
                    name: '姓名',
                    type: 'input',
                    value: 'name'
                },
                {
                    name: '困难级别',
                    value: 'hardLevel',
                    type: 'select',
                    data: [
                        { value: '公司工会帮扶', label: '公司工会帮扶' },
                        { value: '局工会帮扶', label: '局工会帮扶' }
                    ]
                },
                {
                    name: '层级',
                    type: BSelect,
                    valueKey: 'level',
                    list: []
                },
                {
                    name: '单位',
                    type: 'input',
                    value: 'depName'
                }
            ],
            loadData: (params) => {
                return hardWorkApi.getPage2(Object.assign(params, { query: this.queryParam }))
            },
            queryParam: {}
        }
    },
    created() {
        this.getTypeLabel({ type: 1 })
    },
    methods: {

        search(val) {
            this.queryParam = val || {}
            this.$refs.table.getData(null, true)
        },
        handleDel(id) {
            this.$delList3(hardWorkApi.delete, () => {
                this.search()
            }, { id })
        },
        async getTypeLabel(args) {
            const { unionApiUrl } = require('@/api/config.js')
            const Union = require('@/api/union').default
            const { getLabels } = new Union(unionApiUrl, 'queryTypesLabelList')
            let res = await getLabels(args)
            this.searchArr[2].list = res.data

        }
    }
}
</script>
